package alg20241220;

public class Text2 {
    public void sortColors(int[] nums) {
        int left = -1, right = nums.length, i = 0;
        while(i < right){
            if(nums[i] == 0) swap(nums, ++left, i++);
            else if(nums[i] == 1) i++;
            else swap(nums, --right, i);
        };

    }
    public void swap(int[] nums, int i, int j){
        int tmp = nums[i];
        nums[i] = nums[j];
        nums[j] = tmp;
    }
}
